package com.toss.vertx;

import io.vertx.core.DeploymentOptions;
import io.vertx.core.Vertx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

@Component
public class VerticleStarter implements ApplicationListener<ContextRefreshedEvent> {
	@Autowired
	private Vertx vertx;
	@Autowired
	private SpringVerticleFactory verticleFactory;

	@Override
	public void onApplicationEvent(ContextRefreshedEvent event) {
		vertx.registerVerticleFactory(verticleFactory);
		DeploymentOptions op = new DeploymentOptions().setInstances(10000);
		String httpName = verticleFactory.prefix() + ":" + HttpVerticle.class.getName();
		vertx.deployVerticle(httpName, op);
	}

}
